﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////

#define PERFORMANCE_CURVE_TAB "性能图表"
#define CONTENT_PANEL_INDEX 0
#define EMPTY_PANEL_INDEX  1

// std headers
#include <map>

// Qt headers
#include <QStyleOption>
#include <QPainter>
#include <QModelIndex>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QComboBox>
#include <QSizePolicy>
#include <QTableView>
#include <QPushButton>
#include <QHeaderView>
#include <QScrollBar>
#include <QStackedLayout>
#include <QFontMetrics>

// custom headers
#include "PropertyService.h"

#include "ProjectComponentDetailPanel.h"
#include "IProjectComponent.h"
#include "IDetailedProjectComponent.h"
#include "IGmepGcsProjectManager.h"
#include "ProjectCloudComponentService.h"
#include "ProjectLocalComponentService.h"
#include "ProjectCategoryService.h"
#include "HollowButtonTab.h"
#include "TopLineTab.h"
#include "IParameter.gcs.h"
#include "ParametersTableModel.h"
#include "ImageSlider.h"
#include "UrlImageProvider.h"
#include "ParameterItemDelegate.h"
#include "ParametersTableSymbols.h"
#include "IPerformanceCurveDefinition.h"
#include "IParameterDefinition.gcs.h"
#include "CustomReply.h"
#include "ISpecification.h"
#include "UIService.h"
#include "GcsMainWindow.h"
#include "TranslatorManager.h"
#include "GbmpNew.h"
#include "DebugMessage.h"
#include "GncINetworkCheck.h"
#include "BnufBulletin.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h" 

namespace gmepgcs
{
    ProjectComponentDetailPanel::ProjectComponentDetailPanel(QWidget * parent) : QWidget(parent), 
        m_spDetailedComponent(nullptr),
        m_border(0, 0, 0, 0),
        m_borderColor(),
        m_isPrivateEnv(false)
    {
        InitUI();
    }

    ProjectComponentDetailPanel::~ProjectComponentDetailPanel()
    {
    }

    void ProjectComponentDetailPanel::SetBorder(int32_t left, int32_t top, int32_t right, int32_t bottom, QColor &color)
    {
        m_border.setLeft(left);
        m_border.setTop(top);
        m_border.setRight(right);
        m_border.setBottom(bottom);
        m_borderColor = color;
        update();
    }

    void ProjectComponentDetailPanel::SetReplaceButtonVisiable(bool b)
    {
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pBtnReplaceWithPublic, L"m_pBtnReplaceWithPublic", L"GMEP", L"2024-01-30");
        m_pBtnReplaceWithPublic->setVisible(b);
    }

    bool ProjectComponentDetailPanel::SetEditButtonVisiable(bool bVisible) const
    {
        auto btnStartEdit = findChild<QPushButton*>("EditButton");
        DBG_WARN_AND_RETURN_FALSE_UNLESS(btnStartEdit, L"btnStartEdit为空", L"GMEP", L"2024-01-30");
        btnStartEdit->setVisible(bVisible);
        return true;
    }

    std::wstring ProjectComponentDetailPanel::GetCurrentSpecification() const
    {
        DBG_WARN_AND_RETURN_UNLESS(m_pSpecComboBox != nullptr, L"", L"m_pSpecComboBox为空", L"GMEP", L"2024-01-30");
        return m_pSpecComboBox->currentText().toStdWString();
    }

    void ProjectComponentDetailPanel::SetDetailedComponent(std::shared_ptr<IDetailedProjectComponent> spDetailedComponent)
    {
        m_spDetailedComponent = spDetailedComponent;
        if (!m_spDetailedComponent)
        {
            return;
        }

        RefreshData();
        DBG_WARN_AND_RETURN_VOID_UNLESS(spDetailedComponent, L"spDetailedComponent为空", L"GMEP", L"2024-01-30");
        if (spDetailedComponent->IsProcessing())
        {
            QPixmap tipImagePixmap;
            tipImagePixmap.load(":/images/Empty/ComponentDetail/Processing/256x256.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblEmptyTipImage, L"m_pLblEmptyTipImage为空", L"GMEP", L"2024-01-30");
            m_pLblEmptyTipImage->setPixmap(tipImagePixmap.scaled(m_pLblEmptyTipImage->size(), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation));

            QPixmap tipIconPixmap;
            tipIconPixmap.load(":/images/Attention/16x16.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblEmptyTipIcon, L"m_pLblEmptyTipIcon为空", L"GMEP", L"2024-01-30");
            m_pLblEmptyTipIcon->setPixmap(tipIconPixmap.scaled(m_pLblEmptyTipIcon->size(), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation));
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblEmptyTipText, L"m_pLblEmptyTipText为空", L"GMEP", L"2024-01-30");
            m_pLblEmptyTipText->setText(QString::fromStdWString(GBMP_TR(L"构件正在解析，稍后可查看详细信息。")));
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pStackedLayout, L"m_pStackedLayout为空", L"GMEP", L"2024-01-30");
            if (m_pStackedLayout->currentIndex() != EMPTY_PANEL_INDEX)
            {
                m_pStackedLayout->setCurrentIndex(EMPTY_PANEL_INDEX);
            }
        }
        else if (spDetailedComponent->IsProcessedFailed())
        {
            QPixmap tipImagePixmap;
            tipImagePixmap.load(":/images/Empty/ComponentDetail/ProcessFailed/256x256.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblEmptyTipImage, L"m_pLblEmptyTipImage为空", L"GMEP", L"2024-01-30");
            m_pLblEmptyTipImage->setPixmap(tipImagePixmap.scaled(m_pLblEmptyTipImage->size(), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation));

            QPixmap tipIconPixmap;
            tipIconPixmap.load(":/images/Error/16x16.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblEmptyTipIcon, L"m_pLblEmptyTipIcon为空", L"GMEP", L"2024-01-30");
            m_pLblEmptyTipIcon->setPixmap(tipIconPixmap.scaled(m_pLblEmptyTipIcon->size(), Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation));
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblEmptyTipText, L"m_pLblEmptyTipText为空", L"GMEP", L"2024-01-30");
            m_pLblEmptyTipText->setText(QString::fromStdWString(GBMP_TR(L"构件解析失败，无法展示详细信息。")));

            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pStackedLayout, L"m_pStackedLayout为空", L"GMEP", L"2024-01-30");
            if (m_pStackedLayout->currentIndex() != EMPTY_PANEL_INDEX)
            {
                m_pStackedLayout->setCurrentIndex(EMPTY_PANEL_INDEX);
            }
        }
        else
        {
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pStackedLayout, L"m_pStackedLayout为空", L"GMEP", L"2024-01-30");
            if (m_pStackedLayout->currentIndex() != CONTENT_PANEL_INDEX)
            {
                m_pStackedLayout->setCurrentIndex(CONTENT_PANEL_INDEX);
            }
        }
    }

    void ProjectComponentDetailPanel::OnSelectedSpecificationChanged(const QString & spec)
    {
        DBG_WARN_AND_RETURN_VOID_UNLESS(UIService::Get(), L"UIService::Get()为空", L"GMEP", L"2024-01-30");
        if (UIService::Get()->GetMainWindow())
        {
            UIService::Get()->GetMainWindow()->ShowMask();
        }  

        m_currentSpecification = spec;
        //pPerformanceCurvePanel->SetSpecification(spec);
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pGeometricParameterTableModel, L"m_pGeometricParameterTableModel为空", L"GMEP", L"2024-01-30");
        m_pGeometricParameterTableModel->PopulateData({}); 
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pPropertyTableModel, L"m_pPropertyTableModel为空", L"GMEP", L"2024-01-30");
        m_pPropertyTableModel->PopulateData({});

        if (!(m_spDetailedComponent) || spec.isEmpty())
        {
            return;
            UIService::Get()->GetMainWindow()->HideMask();
        }
        DBG_WARN_AND_RETURN_VOID_UNLESS(IProjectManager::Get(), L"IProjectManager::Get()为空", L"GMEP", L"2024-01-30");
        std::wstring projectId = IProjectManager::Get()->GetCurrentProjectId();
        std::wstring componentId = m_spDetailedComponent->Id;
        std::wstring version = std::to_wstring(m_spDetailedComponent->Version);

        std::shared_ptr<ISpecification> spSpecification =
            ProjectLocalComponentService::Get()->GetSpecification(
                projectId,
                m_spDetailedComponent->Id,
                m_spDetailedComponent->Version,
                spec.toStdWString());

        if (!spSpecification)
        {
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pGeometricParameterTableModel, L"m_pGeometricParameterTableModel为空", L"GMEP", L"2024-01-30");
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pPropertyTableModel, L"m_pPropertyTableModel为空", L"GMEP", L"2024-01-30");
            m_pGeometricParameterTableModel->PopulateData({});
            m_pPropertyTableModel->PopulateData({});
            if (UIService::Get()->GetMainWindow())
                UIService::Get()->GetMainWindow()->HideMask();
            return;
        }
       
            std::vector<std::shared_ptr<IParameter>> geometricParameters;
            std::vector<std::shared_ptr<IParameter>> propertyParameters;
            for (auto &paramPair : spSpecification->Parameters)
            {
                auto param = paramPair.second;
                if (param && param->IsVisible())
                {
                    DBG_WARN_AND_CONTINUE_UNLESS(param.get(), L"param.get()为空", L"GMEP", L"2024-01-30");
                    if (param.get()->Definition && param.get()->Definition->IsGeometry())
                    {
                        geometricParameters.push_back(param);
                    }
                    else
                    {
                        propertyParameters.push_back(param);
                    }
                }
            }

            m_pGeometricParameterTableModel->PopulateData(geometricParameters);
            m_pPropertyTableModel->PopulateData(propertyParameters);
            if (UIService::Get()->GetMainWindow())
                UIService::Get()->GetMainWindow()->HideMask();
    }

    void ProjectComponentDetailPanel::OnCurrentTabChanged(QString currentTabHeader)
    {
    }

    void ProjectComponentDetailPanel::paintEvent(QPaintEvent * event)
    {
        // to make setStyleSheet(...) in effect
        QStyleOption option;
        option.init(this);
        QPainter painter(this);
        DBG_WARN_AND_RETURN_VOID_UNLESS(style(), L"style()为空", L"GMEP", L"2024-01-30");
        style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);

        QWidget::paintEvent(event);
        
        // to paint border
        painter.save();
        QPen borderPen;
        borderPen.setColor(m_borderColor);

        borderPen.setWidth(m_border.left());
        painter.setPen(borderPen);
        painter.drawLine(option.rect.bottomLeft(), option.rect.topLeft());

        borderPen.setWidth(m_border.top());
        painter.setPen(borderPen);
        painter.drawLine(option.rect.topLeft(), option.rect.topRight());

        borderPen.setWidth(m_border.right());
        painter.setPen(borderPen);
        painter.drawLine(option.rect.topRight(), option.rect.bottomRight());

        borderPen.setWidth(m_border.bottom());
        painter.setPen(borderPen);
        painter.drawLine(option.rect.bottomRight(), option.rect.bottomLeft());

        painter.restore();

    }

    void ProjectComponentDetailPanel::InitUI()
    {
        // stacked layout
        m_pStackedLayout = NEW_AS_QT(QStackedLayout);
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pStackedLayout, L"m_pStackedLayout为空", L"GMEP", L"2024-01-30");
        m_pStackedLayout->setContentsMargins(1, 1, 1, 1);
        m_pStackedLayout->setSpacing(0);
        setLayout(m_pStackedLayout);

        // main layout
        QLayout *pMainLayout = InitMainPanel();
        QWidget *pMainWidget = NEW_AS_QT(QWidget,this);
        DBG_WARN_AND_RETURN_VOID_UNLESS(pMainWidget, L"pMainWidget为空", L"GMEP", L"2024-01-30");
        pMainWidget->setObjectName("ProjectDetailMainWidget");
        pMainWidget->setLayout(pMainLayout);
        m_pStackedLayout->addWidget(pMainWidget);

        // empty layout
        QLayout *pEmptyLayout = InitEmptyPanel();
        QWidget *pEmptyWidget = NEW_AS_QT(QWidget,this);
        DBG_WARN_AND_RETURN_VOID_UNLESS(pEmptyWidget, L"pEmptyWidget为空", L"GMEP", L"2024-01-30");
        pEmptyWidget->setObjectName("EmptyWidget");
        pEmptyWidget->setStyleSheet("QWidget#EmptyWidget{background:white;}");
        pEmptyWidget->setLayout(pEmptyLayout);
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pStackedLayout, L"m_pStackedLayout为空", L"GMEP", L"2024-01-30");
        m_pStackedLayout->addWidget(pEmptyWidget);

        m_pStackedLayout->setCurrentIndex(CONTENT_PANEL_INDEX);
    }

    QLayout * ProjectComponentDetailPanel::InitMainPanel()
    {
        m_pComponentNameLabel = NEW_AS_QT(QLabel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pComponentNameLabel, L"m_pComponentNameLabel为空", L"GMEP", L"2024-01-30");
        m_pComponentNameLabel->setContentsMargins(0, 0, 0, 0);
        QFont componentNameFont(QString::fromStdWString(L"Microsoft YaHei"));
        componentNameFont.setPixelSize(14);
        m_pComponentNameLabel->setFont(componentNameFont);

        QVBoxLayout *pMainVBoxLayout = NEW_AS_QT(QVBoxLayout, this);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pMainVBoxLayout, L"pMainVBoxLayout为空", L"GMEP", L"2024-01-30");
        pMainVBoxLayout->setSpacing(0);
        pMainVBoxLayout->setContentsMargins(1, 1, 1, 1);

        QHBoxLayout *pOpertationLayout = NEW_AS_QT(QHBoxLayout);
        pMainVBoxLayout->addLayout(pOpertationLayout);
        pOpertationLayout->setContentsMargins(8, 8, 8, 8);
        pOpertationLayout->setSpacing(10);

        pOpertationLayout->addStretch();

        QPushButton *btnStartEdit = NEW_AS_QT( QPushButton,QString::fromStdWString(GBMP_TR(L"编辑")));
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(btnStartEdit, L"btnStartEdit为空", L"GMEP", L"2024-01-30");
        pOpertationLayout->addWidget(btnStartEdit);
        btnStartEdit->setObjectName("EditButton");
        btnStartEdit->setContentsMargins(0, 0, 0, 0);
        btnStartEdit->setFixedHeight(24);
        btnStartEdit->setMinimumWidth(56);
        btnStartEdit->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Fixed);
        btnStartEdit->setCursor(QCursor(Qt::CursorShape::PointingHandCursor));
        btnStartEdit->setStyleSheet("QPushButton{"
            "background-color:rgba(82,145,221,255);"
            "color:rgba(255,255,255,255);"
            "font-family:Microsoft YaHei;"
            "font-size:12px;"
            "border:1px solid rgba(82,145,221,255);"
            "border-radius:2px;"
            "}");
        connect(btnStartEdit, &QPushButton::clicked, this, &ProjectComponentDetailPanel::StartEdit);

        // replace button
        m_pBtnReplaceWithPublic = NEW_AS_QT(QPushButton, QString::fromStdWString(GBMP_TR(L"替换")));
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pBtnReplaceWithPublic, L"m_pBtnReplaceWithPublic", L"GMEP", L"2024-01-30");
        pOpertationLayout->addWidget(m_pBtnReplaceWithPublic);
        m_pBtnReplaceWithPublic->setObjectName("ReplaceButton");
        m_pBtnReplaceWithPublic->setFixedHeight(24);
        m_pBtnReplaceWithPublic->setFixedWidth(48);
        m_pBtnReplaceWithPublic->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Fixed);
        m_pBtnReplaceWithPublic->setCursor(QCursor(Qt::CursorShape::PointingHandCursor));
        m_pBtnReplaceWithPublic->setStyleSheet("QPushButton{"
            "background-color:rgba(82,145,221,255);"
            "color:rgba(255,255,255,255);"
            "font-family:Microsoft YaHei;"
            "font-size:12px;"
            "border:1px solid rgba(82,145,221,255);"
            "border-radius:2px;"
            "}");
        m_pBtnReplaceWithPublic->setVisible(false);// true
        connect(m_pBtnReplaceWithPublic, &QPushButton::clicked, this, [=]() {
            if (!m_spDetailedComponent)
            {
                return;
            }
            // 若是公有云环境，则需要检查网络
            if (!m_isPrivateEnv && (!gnc::INetworkCheck::Get() || !gnc::INetworkCheck::Get()->CheckNetworkConnection()))
            {
                BnufBulletin::SingleShot(GBMP_TR(L"没有联网，请检查网络"), BnufBulletin::BulletinIcon::Error);
                return;
            }

            std::wstring projectId = IProjectManager::Get()->GetCurrentProjectId();
            emit ReplaceWithPublicRequired(projectId, m_spDetailedComponent->Id);
        });

        QPushButton *closeDetailedPage = NEW_AS_QT (QPushButton);
        closeDetailedPage->setObjectName("CloseDetailButton");
        closeDetailedPage->setFixedSize(16, 16);
        closeDetailedPage->setIcon(QIcon(QString::fromStdWString(L":/images/close_detail_cross_16x16.png")));
        closeDetailedPage->setCursor(Qt::PointingHandCursor);
        closeDetailedPage->setStyleSheet("QPushButton{background:transparent;}");
        connect(closeDetailedPage, &QPushButton::clicked, this, &QWidget::close);

        QHBoxLayout *pHLayoutComponentNameAndOthers = NEW_AS_QT(QHBoxLayout);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pHLayoutComponentNameAndOthers, L"pHLayoutComponentNameAndOthers为空", L"GMEP", L"2024-01-30");
        pHLayoutComponentNameAndOthers->setSpacing(10);
        pHLayoutComponentNameAndOthers->setContentsMargins(8, 5, 8, 0);
        pHLayoutComponentNameAndOthers->addWidget(m_pComponentNameLabel);
        pHLayoutComponentNameAndOthers->addStretch();
        pHLayoutComponentNameAndOthers->addWidget(btnStartEdit);
        pHLayoutComponentNameAndOthers->addWidget(closeDetailedPage);

        m_pCategoryLabel = NEW_AS_QT(QLabel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pCategoryLabel, L"m_pCategoryLabel为空", L"GMEP", L"2024-01-30");
        m_pCategoryLabel->setText(QString::fromStdWString(GBMP_TR(L"分类: ")));
        m_pCategoryLabel->setContentsMargins(8, 5, 8, 0);
        QFont categoryFont(QString::fromStdWString(L"Microsoft YaHei"));
        categoryFont.setPixelSize(12);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pCategoryLabel, L"m_pCategoryLabel为空", L"GMEP", L"2024-01-30");
        m_pCategoryLabel->setFont(categoryFont);
        m_pCategoryLabel->setStyleSheet(QString::fromStdWString(L"QLabel{color:rgba(160, 162, 171, 1)}"));

        m_pThubmnailAndLegendTab = NEW_AS_QT(HollowButtonTab);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pThubmnailAndLegendTab, L"m_pThubmnailAndLegendTab为空", L"GMEP", L"2024-01-30");
        m_pThubmnailAndLegendTab->setObjectName("ThumbnailAndLegendTab");
        m_pThubmnailAndLegendTab->setFixedHeight(230);
        m_pThubmnailAndLegendTab->setContentsMargins(0, 8, 0, 0);
        connect(m_pThubmnailAndLegendTab, &HollowButtonTab::CurrentTabChanged, this, &ProjectComponentDetailPanel::OnCurrentTabChanged);

        m_pComponentThumnailSlider = NEW_AS_QT(ImageSlider,this);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pComponentThumnailSlider, L"m_pComponentThumnailSlider为空", L"GMEP", L"2024-01-30");
        m_pComponentThumnailSlider->setObjectName("ThumbnailImageSlider");
        m_pComponentThumnailSlider->ResetImages();
        m_pThubmnailAndLegendTab->AddTabItem(QString::fromStdWString(GBMP_TR(L"缩略图")), m_pComponentThumnailSlider);

        m_pLegendThumnailSlider = NEW_AS_QT(ImageSlider,this);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pLegendThumnailSlider, L"m_pLegendThumnailSlider为空", L"GMEP", L"2024-01-30");
        m_pLegendThumnailSlider->setObjectName("LegendImageSlider");
        m_pLegendThumnailSlider->ResetImages();
        m_pLegendThumnailSlider->SetImageFrameSize(QSize(128, 128));
        m_pLegendThumnailSlider->SetStretch(true);
        m_pLegendThumnailSlider->SetShowBorder(true);
        m_pLegendThumnailSlider->SetShowTitle(true);
        m_pThubmnailAndLegendTab->AddTabItem(QString::fromStdWString(GBMP_TR(L"图例")), m_pLegendThumnailSlider);

        QLabel *pSpecLabel = NEW_AS_QT( QLabel,QString::fromStdWString(GBMP_TR(L"类型")));
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pSpecLabel, L"pSpecLabel为空", L"GMEP", L"2024-01-30");
        pSpecLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        QFont specLabelFont = pSpecLabel->font();
        specLabelFont.setFamily("Microsoft YaHei");
        specLabelFont.setPixelSize(14);
        pSpecLabel->setFont(specLabelFont);
        pSpecLabel->setStyleSheet("QLabel{color:rgba(102,102,102,255)}");

        m_pSpecComboBox = NEW_AS_QT(QComboBox);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pSpecComboBox, L"m_pSpecComboBox为空", L"GMEP", L"2024-01-30");
        m_pSpecComboBox->setObjectName("SpecificationSelector");
        m_pSpecComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
        QFont specComboboxFont = m_pSpecComboBox->font();
        specComboboxFont.setFamily("Microsoft YaHei");
        specComboboxFont.setPixelSize(12);
        m_pSpecComboBox->setFont(specComboboxFont);
        m_pSpecComboBox->setStyleSheet("QComboBox{color:rgba(80,82,91,255)}");
        connect(m_pSpecComboBox, static_cast<void (QComboBox:: *)(const QString &)>(&QComboBox::currentIndexChanged), this, &ProjectComponentDetailPanel::OnSelectedSpecificationChanged);

        QLabel *pInstanceCountLabel = NEW_AS_QT( QLabel,QString::fromStdWString(GBMP_TR(L"实例:0")));
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pInstanceCountLabel, L"pInstanceCountLabel为空", L"GMEP", L"2024-01-30");
        pInstanceCountLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        pInstanceCountLabel->setVisible(false);

        QHBoxLayout *pSpecHBoxLayout = NEW_AS_QT(QHBoxLayout);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pSpecHBoxLayout, L"pSpecHBoxLayout为空", L"GMEP", L"2024-01-30");
        pSpecHBoxLayout->addWidget(pSpecLabel);
        pSpecHBoxLayout->addWidget(m_pSpecComboBox);
        pSpecHBoxLayout->addWidget(pInstanceCountLabel);
        pSpecHBoxLayout->setSpacing(8);
        pSpecHBoxLayout->setContentsMargins(8, 5, 8, 0);

        QTableView *pParametersTable = NEW_AS_QT(QTableView,this);
        QTableView *pPropertiesTable = NEW_AS_QT(QTableView,this);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParametersTable, L"pParametersTable为空", L"GMEP", L"2024-01-30");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pPropertiesTable, L"pPropertiesTable为空", L"GMEP", L"2024-01-30");
        m_pGeometricParameterTableModel = NEW_AS_QT(ParametersTableModel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pGeometricParameterTableModel, L"m_pGeometricParameterTableModel为空", L"GMEP", L"2024-01-30");
        pParametersTable->setModel(m_pGeometricParameterTableModel);
        m_pPropertyTableModel = NEW_AS_QT(ParametersTableModel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pPropertyTableModel, L"m_pPropertyTableModel为空", L"GMEP", L"2024-01-30");
        pPropertiesTable->setModel(m_pPropertyTableModel);

        ParameterItemDelegate *pDelegate = NEW_AS_QT(ParameterItemDelegate);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pDelegate, L"pDelegate为空", L"GMEP", L"2024-01-30");
        pParametersTable->setItemDelegate(pDelegate);
        pParametersTable->setSelectionMode(QAbstractItemView::NoSelection);
        pParametersTable->setStyleSheet("border:none");
        pParametersTable->setShowGrid(false);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParametersTable->verticalHeader(), L"pParametersTable->verticalHeader()为空", L"GMEP", L"2024-01-30");
        pParametersTable->verticalHeader()->hide();
        pParametersTable->verticalHeader()->setDefaultSectionSize(24);
        pParametersTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParametersTable->horizontalHeader(), L"pParametersTable->horizontalHeader()为空", L"GMEP", L"2024-01-30");
        pParametersTable->horizontalHeader()->hide();
        pParametersTable->horizontalHeader()->setSectionResizeMode(COL_PARAMETER_FLAG, QHeaderView::Fixed);
        pParametersTable->horizontalHeader()->setSectionResizeMode(COL_PARAMETER_NAME, QHeaderView::Fixed);
        pParametersTable->horizontalHeader()->setSectionResizeMode(COL_PARAMETER_VALUE, QHeaderView::Stretch);
        pParametersTable->setColumnWidth(COL_PARAMETER_FLAG, 20);
        pParametersTable->setColumnHidden(COL_PARAMETER_FLAG, true);
        pParametersTable->setColumnWidth(COL_PARAMETER_NAME, 136);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParametersTable->verticalScrollBar(), L"pParametersTable->verticalScrollBar()为空", L"GMEP", L"2024-01-30");
        pParametersTable->verticalScrollBar()->setStyleSheet("QScrollBar:vertical"
            "{"
            "width:8px;"
            "background:rgba(0,0,0,0%);"
            "margin:0px,0px,0px,0px;"
            "padding-top:9px;"
            "padding-bottom:9px;"
            "padding-left:1px;"
            "padding-right:1px;"
            "}"
            "QScrollBar::handle:vertical"
            "{"
            "width:6px;"
            "background:rgba(35,40,50,20%);"
            "border-radius:2px;"
            "min-height:20;"
            "}"
            "QScrollBar::handle:vertical:hover"
            "{"
            "width:6px;"
            "background:rgba(35,40,50,40%);"
            " border-radius:2px;"
            "min-height:20;"
            "}"
            "QScrollBar::add-line:vertical"
            "{"
            "height:0px;width:0px;"
            "border-image:url(:/images/icon_triangle_solid_down_8.png);"
            "subcontrol-position:bottom;"
            "}"
            "QScrollBar::sub-line:vertical"
            "{"
            "height:0px;width:0px;"
            "border-image:url(:/images/icon_triangle_solid_up_8.png);"
            "subcontrol-position:top;"
            "}"
            "QScrollBar::add-line:vertical:hover"
            "{"
            "height:0px;width:0px;"
            "border-image:url(:/images/icon_triangle_solid_down_8.png);"
            "subcontrol-position:bottom;"
            "}"
            "QScrollBar::sub-line:vertical:hover"
            "{"
            "height:0px;width:0px;"
            "border-image:url(:/images/icon_triangle_solid_up_8.png);"
            "subcontrol-position:top;"
            "}"
            "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
            "{"
            "background:rgba(255,255,255,10%);"
            "border-radius:4px;"
            "}"
        );

        ParameterItemDelegate *pPropertiesDelegate = NEW_AS_QT(ParameterItemDelegate);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pPropertiesDelegate, L"pPropertiesDelegate为空", L"GMEP", L"2024-01-30");
        pPropertiesTable->setItemDelegate(pPropertiesDelegate);
        pPropertiesTable->setSelectionMode(QAbstractItemView::NoSelection);
        pPropertiesTable->setStyleSheet("border:none");
        pPropertiesTable->setShowGrid(false);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pPropertiesTable->verticalHeader(), L"pPropertiesTable->verticalHeader()为空", L"GMEP", L"2024-01-30");
        pPropertiesTable->verticalHeader()->hide();
        pPropertiesTable->verticalHeader()->setDefaultSectionSize(24);
        pPropertiesTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pPropertiesTable->horizontalHeader(), L"pPropertiesTable->horizontalHeader()为空", L"GMEP", L"2024-01-30");
        pPropertiesTable->horizontalHeader()->hide();
        pPropertiesTable->horizontalHeader()->setSectionResizeMode(COL_PARAMETER_FLAG, QHeaderView::Fixed);
        pPropertiesTable->horizontalHeader()->setSectionResizeMode(COL_PARAMETER_NAME, QHeaderView::Fixed);
        pPropertiesTable->horizontalHeader()->setSectionResizeMode(COL_PARAMETER_VALUE, QHeaderView::Stretch);
        pPropertiesTable->setColumnWidth(COL_PARAMETER_FLAG, 20);
        pPropertiesTable->setColumnHidden(COL_PARAMETER_FLAG, true);
        pPropertiesTable->setColumnWidth(COL_PARAMETER_NAME, 136);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pPropertiesTable->verticalScrollBar(), L"pPropertiesTable->verticalScrollBar()为空", L"GMEP", L"2024-01-30");
        pPropertiesTable->verticalScrollBar()->setStyleSheet("QScrollBar:vertical"
            "{"
            "width:8px;"
            "background:rgba(0,0,0,0%);"
            "margin:0px,0px,0px,0px;"
            "padding-top:9px;"
            "padding-bottom:9px;"
            "padding-left:1px;"
            "padding-right:1px;"
            "}"
            "QScrollBar::handle:vertical"
            "{"
            "width:6px;"
            "background:rgba(35,40,50,20%);"
            "border-radius:2px;"
            "min-height:20;"
            "}"
            "QScrollBar::handle:vertical:hover"
            "{"
            "width:6px;"
            "background:rgba(35,40,50,40%);"
            " border-radius:2px;"
            "min-height:20;"
            "}"
            "QScrollBar::add-line:vertical"
            "{"
            "height:0px;width:0px;"
            "border-image:url(:/images/icon_triangle_solid_down_8.png);"
            "subcontrol-position:bottom;"
            "}"
            "QScrollBar::sub-line:vertical"
            "{"
            "height:0px;width:0px;"
            "border-image:url(:/images/icon_triangle_solid_up_8.png);"
            "subcontrol-position:top;"
            "}"
            "QScrollBar::add-line:vertical:hover"
            "{"
            "height:0px;width:0px;"
            "border-image:url(:/images/icon_triangle_solid_down_8.png);"
            "subcontrol-position:bottom;"
            "}"
            "QScrollBar::sub-line:vertical:hover"
            "{"
            "height:0px;width:0px;"
            "border-image:url(:/images/icon_triangle_solid_up_8.png);"
            "subcontrol-position:top;"
            "}"
            "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
            "{"
            "background:rgba(255,255,255,10%);"
            "border-radius:4px;"
            "}"
        );

        pParametersAndPerformanceCurvesTab = NEW_AS_QT(TopLineTab);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParametersAndPerformanceCurvesTab, L"pParametersAndPerformanceCurvesTab为空", L"GMEP", L"2024-01-30");
        pParametersAndPerformanceCurvesTab->setContentsMargins(0, 8, 0, 0);
        pParametersAndPerformanceCurvesTab->SetHeaderBackgorund(QColor(217, 221, 228, 255));
        pParametersAndPerformanceCurvesTab->AddTabItem(QString::fromStdWString(GBMP_TR(L"几何参数")), pParametersTable);
        pParametersAndPerformanceCurvesTab->AddTabItem(QString::fromStdWString(GBMP_TR(L"产品属性")), pPropertiesTable);


        pMainVBoxLayout->addLayout(pHLayoutComponentNameAndOthers);
        pMainVBoxLayout->addWidget(m_pCategoryLabel);
        pMainVBoxLayout->addWidget(m_pThubmnailAndLegendTab);
        pMainVBoxLayout->addLayout(pSpecHBoxLayout);
        pMainVBoxLayout->addWidget(pParametersAndPerformanceCurvesTab);

        return pMainVBoxLayout;
    }

    QLayout * ProjectComponentDetailPanel::InitEmptyPanel()
    {
        QVBoxLayout *pEmptyLayout = NEW_AS_QT(QVBoxLayout, this);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pEmptyLayout, L"pEmptyLayout为空", L"GMEP", L"2024-01-30");
        pEmptyLayout->setContentsMargins(8, 0, 8, 0);
        pEmptyLayout->setSpacing(0);

        pEmptyLayout->addSpacing(5);

        QHBoxLayout *pHLayoutComponentNameAndOthers = NEW_AS_QT(QHBoxLayout);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pHLayoutComponentNameAndOthers, L"pHLayoutComponentNameAndOthers为空", L"GMEP", L"2024-01-30");
        pHLayoutComponentNameAndOthers->setSpacing(10);
        pHLayoutComponentNameAndOthers->setContentsMargins(0, 0, 0, 0);
        pEmptyLayout->addLayout(pHLayoutComponentNameAndOthers);
        
        // component name
        m_pLblComponentNameInEmptyPanel = NEW_AS_QT(QLabel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pLblComponentNameInEmptyPanel, L"m_pLblComponentNameInEmptyPanel为空", L"GMEP", L"2024-01-30");
        QFont componentNameFont(QString::fromStdWString(L"Microsoft YaHei"));
        componentNameFont.setPixelSize(14);
        m_pLblComponentNameInEmptyPanel->setFont(componentNameFont);
        pHLayoutComponentNameAndOthers->addWidget(m_pLblComponentNameInEmptyPanel);
        pHLayoutComponentNameAndOthers->addStretch();

        // closte button
        QPushButton *closeDetailedPage = NEW_AS_QT (QPushButton);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(closeDetailedPage, L"closeDetailedPage为空", L"GMEP", L"2024-01-30");
        closeDetailedPage->setObjectName("CloseDetailButton");
        closeDetailedPage->setFixedSize(16, 16);
        closeDetailedPage->setIcon(QIcon(QString::fromStdWString(L":/images/close_detail_cross_16x16.png")));
        closeDetailedPage->setCursor(Qt::PointingHandCursor);
        closeDetailedPage->setStyleSheet("QPushButton{background:transparent;}");
        connect(closeDetailedPage, &QPushButton::clicked, [=]() {hide(); });
        pHLayoutComponentNameAndOthers->addWidget(closeDetailedPage);        

        pEmptyLayout->addSpacing(5);

        // category
        m_pLblComponentCategoryInEmptyPanel = NEW_AS_QT(QLabel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pLblComponentCategoryInEmptyPanel, L"m_pLblComponentCategoryInEmptyPanel为空", L"GMEP", L"2024-01-30");
        m_pLblComponentCategoryInEmptyPanel->setText(QString::fromStdWString(GBMP_TR(L"分类: ")));
        m_pLblComponentCategoryInEmptyPanel->setStyleSheet(
            "QLabel{"
            "font-family:\"Microsoft YaHei\";"
            "font-size:12px;"
            "color:rgba(160, 162, 171, 1)"
            "}"
        );
        pEmptyLayout->addWidget(m_pLblComponentCategoryInEmptyPanel);

        pEmptyLayout->addSpacing(5);

        pEmptyLayout->addStretch(104);

        // tip layout
        QVBoxLayout *pTipLayout = NEW_AS_QT(QVBoxLayout);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pTipLayout, L"pTipLayout为空", L"GMEP", L"2024-01-30");
        pTipLayout->setContentsMargins(0, 0, 0, 0);
        pTipLayout->setSpacing(0);
        pEmptyLayout->addLayout(pTipLayout);

        // tip image
        m_pLblEmptyTipImage = NEW_AS_QT(QLabel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pLblEmptyTipImage, L"m_pLblEmptyTipImage为空", L"GMEP", L"2024-01-30");
        m_pLblEmptyTipImage->setFixedSize(QSize(128, 128));
        pTipLayout->addWidget(m_pLblEmptyTipImage);
        pTipLayout->setAlignment(m_pLblEmptyTipImage, Qt::AlignHCenter);
        
        // tip sub layout
        QHBoxLayout *pTipSubLayout = NEW_AS_QT(QHBoxLayout);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pTipSubLayout, L"pTipSubLayout为空", L"GMEP", L"2024-01-30");
        pTipSubLayout->setContentsMargins(0, 0, 0, 0);
        pTipSubLayout->setSpacing(0);
        pTipLayout->addLayout(pTipSubLayout);

        pTipSubLayout->addStretch();

        // tip icon
        m_pLblEmptyTipIcon = NEW_AS_QT(QLabel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pLblEmptyTipIcon, L"m_pLblEmptyTipIcon为空", L"GMEP", L"2024-01-30");
        m_pLblEmptyTipIcon->setVisible(false);
        m_pLblEmptyTipIcon->setFixedSize(QSize(16, 16));
        pTipSubLayout->addWidget(m_pLblEmptyTipIcon);
        pTipSubLayout->setAlignment(m_pLblEmptyTipIcon, Qt::AlignVCenter);

        pTipSubLayout->addSpacing(5);
        
        // tip text
        m_pLblEmptyTipText = NEW_AS_QT(QLabel);
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(m_pLblEmptyTipText, L"m_pLblEmptyTipText为空", L"GMEP", L"2024-01-30");
        m_pLblEmptyTipText->setStyleSheet(
            "QLabel{"
            "font-family:\"Microsoft YaHei\";"
            "font-size:12px;"
            "color:rgba(89, 99, 112, 255);"
            "}"
        );
        pTipSubLayout->addWidget(m_pLblEmptyTipText);
        pTipSubLayout->setAlignment(m_pLblEmptyTipText, Qt::AlignVCenter);

        pTipSubLayout->addStretch();

        pEmptyLayout->addStretch(392);

        return pEmptyLayout;
    }

    void ProjectComponentDetailPanel::RefreshData()
    {
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pThubmnailAndLegendTab, L"m_pThubmnailAndLegendTab为空", L"GMEP", L"2024-01-30");
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pThubmnailAndLegendTab, L"m_pThubmnailAndLegendTab为空", L"GMEP", L"2024-01-30");
        m_pThubmnailAndLegendTab->SwtichToTab(m_pThubmnailAndLegendTab->GetWidgetAt(0));
        RefreshComponentName();
        RefreshCategory();

        RefreshLegends();
        RefreshThumbnails();

        RefreshSpecifications();
    }

    void ProjectComponentDetailPanel::RefreshComponentName()
    {
        if (!(m_spDetailedComponent))
        {
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pComponentNameLabel, L"m_pComponentNameLabel为空", L"GMEP", L"2024-01-30");
            m_pComponentNameLabel->setText(QString());
            m_pComponentNameLabel->setToolTip(QString());
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblComponentNameInEmptyPanel, L"m_pLblComponentNameInEmptyPanel为空", L"GMEP", L"2024-01-30");
            m_pLblComponentNameInEmptyPanel->setText(QString());
            m_pLblComponentNameInEmptyPanel->setToolTip(QString());
            return;
        }

        std::wstring displayName = L"";
        if (m_spDetailedComponent)
        {
            displayName = m_spDetailedComponent->Name;
            if (displayName.size() >= 4 && displayName.substr(displayName.size() - 4, 4) == L".gac")
            {
                displayName = displayName.substr(0, displayName.size() - 4);
            }
        }

        auto qDisplayName = QString::fromStdWString(displayName);
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pComponentNameLabel, L"m_pComponentNameLabel为空", L"GMEP", L"2024-01-30");
        m_pComponentNameLabel->setText(QFontMetrics(m_pComponentNameLabel->font())
            .elidedText(qDisplayName, Qt::TextElideMode::ElideRight, width() - 8 * 2 - 56 - 10 - 16 - 10));
        m_pComponentNameLabel->setToolTip(qDisplayName);

        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblComponentNameInEmptyPanel, L"m_pLblComponentNameInEmptyPanel为空", L"GMEP", L"2024-01-30");
        m_pLblComponentNameInEmptyPanel->setText(QFontMetrics(m_pLblComponentNameInEmptyPanel->font())
            .elidedText(qDisplayName, Qt::TextElideMode::ElideRight, width() - 8 * 2 - 56 - 10 - 16 - 10));
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblComponentNameInEmptyPanel, L"m_pLblComponentNameInEmptyPanel为空", L"GMEP", L"2024-01-30");
        m_pLblComponentNameInEmptyPanel->setToolTip(qDisplayName);
    }

    void ProjectComponentDetailPanel::RefreshCategory()
    {
        std::wstring displayCategories = GBMP_TR(L"分类: ");

        if (!(m_spDetailedComponent))
        {
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pCategoryLabel, L"m_pCategoryLabel为空", L"GMEP", L"2024-01-30");
            m_pCategoryLabel->setText(QString::fromStdWString(displayCategories));
            m_pCategoryLabel->setToolTip(QString());
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblComponentCategoryInEmptyPanel, L"m_pLblComponentCategoryInEmptyPanel为空", L"GMEP", L"2024-01-30");
            m_pLblComponentCategoryInEmptyPanel->setText(QString::fromStdWString(displayCategories));
            m_pLblComponentCategoryInEmptyPanel->setToolTip(QString());
            return;
        }
        DBG_WARN_AND_RETURN_VOID_UNLESS(ProjectCategoryService::Get(), L"ProjectCategoryService::Get()为空", L"GMEP", L"2024-01-30");
        auto categories = PropertyService::Get()->GetFullCategories(m_spDetailedComponent->CategoryCode);
        for (auto &category : categories)
        {
            DBG_WARN_AND_CONTINUE_UNLESS(category, L"category为空", L"GMEP", L"2024-01-30");
            displayCategories += (category->Name + L"/");
        }

        if (displayCategories.back() == L'/')
        {
            displayCategories.pop_back();
        }
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pCategoryLabel, L"m_pCategoryLabel为空", L"GMEP", L"2024-01-30");
        auto qDisplayCategories = QString::fromStdWString(displayCategories);
        m_pCategoryLabel->setText(QFontMetrics(m_pCategoryLabel->font())
            .elidedText(qDisplayCategories, Qt::TextElideMode::ElideRight, width() - 8 * 2));
        m_pCategoryLabel->setToolTip(qDisplayCategories);
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLblComponentCategoryInEmptyPanel, L"m_pLblComponentCategoryInEmptyPanel为空", L"GMEP", L"2024-01-30");
        m_pLblComponentCategoryInEmptyPanel->setText(QFontMetrics(m_pLblComponentCategoryInEmptyPanel->font())
            .elidedText(qDisplayCategories, Qt::TextElideMode::ElideRight, width() - 8 * 2));
        m_pLblComponentCategoryInEmptyPanel->setToolTip(qDisplayCategories);
    }

    void ProjectComponentDetailPanel::RefreshThumbnails()
    {
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pComponentThumnailSlider, L"m_pComponentThumnailSlider为空", L"GMEP", L"2024-01-30");

        if (!(m_spDetailedComponent))
        {
            m_pComponentThumnailSlider->SetImages({});
            return;
        }

        std::vector<std::wstring> images;
        if (m_spDetailedComponent)
        {
            std::wstring tagetSize = L"256";
            if (m_spDetailedComponent->Thumbnails.find(tagetSize) != m_spDetailedComponent->Thumbnails.end())
            {
                for (auto &item : m_spDetailedComponent->Thumbnails[tagetSize])
                {
                    images.push_back(item);
                }
            }
        }

        m_pComponentThumnailSlider->SetImages(images);
    }

    void ProjectComponentDetailPanel::RefreshSpecifications()
    {
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pSpecComboBox, L"m_pSpecComboBox为空", L"GMEP", L"2024-01-30");
        m_pSpecComboBox->clear();
        m_pSpecComboBox->setCurrentIndex(-1);

        if (!(m_spDetailedComponent))
        {
            return;
        }

        QStringList specList;
        for (auto &spec : m_spDetailedComponent->Specifications)
        {
            specList << QString::fromStdWString(spec);
        }

        if (!specList.empty())
        {
            DBG_WARN_AND_RETURN_VOID_UNLESS(m_pSpecComboBox, L"m_pSpecComboBox为空", L"GMEP", L"2024-01-30");
            m_pSpecComboBox->addItems(specList);
        }
    }
    void ProjectComponentDetailPanel::ShowLegends(std::vector<std::shared_ptr<ILegend>> spLegends)
    {
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pThubmnailAndLegendTab, L"m_pThubmnailAndLegendTab为空", L"GMEP", L"2024-01-30");
        if (spLegends.size() == 0)
        {
            m_pThubmnailAndLegendTab->SetTabItemVisible(QString::fromStdWString(GBMP_TR(L"图例")), false);
        }
        else
        {
            m_pThubmnailAndLegendTab->SetTabItemVisible(QString::fromStdWString(GBMP_TR(L"图例")), true);
        }

        std::vector<std::wstring> images;
        std::map<std::wstring, std::wstring> imageTitles;
        if (spLegends.size() > 0)
        {
            for (auto legend : spLegends)
            {
                if (legend)
                {
                    images.push_back(legend->Thumbnail);
                    imageTitles[legend->Thumbnail] = ILegend::GetTypeName(legend->Type);
                }
            }
        }
        
        DBG_WARN_AND_RETURN_VOID_UNLESS(m_pLegendThumnailSlider, L"m_pLegendThumnailSlider为空", L"GMEP", L"2024-01-30");

        m_pLegendThumnailSlider->SetImages(images, imageTitles);
    }


    void ProjectComponentDetailPanel::RefreshPerformanceCurveDefinitions(std::shared_ptr<std::vector<IPerformanceCurveDefinition*>> spCurveDefintions)
    {
        DBG_WARN_AND_RETURN_VOID_UNLESS(pParametersAndPerformanceCurvesTab, L"pParametersAndPerformanceCurvesTab为空", L"GMEP", L"2024-01-30");
        if (!spCurveDefintions || spCurveDefintions->empty())
        {
            pParametersAndPerformanceCurvesTab->SetTabItemVisible(PERFORMANCE_CURVE_TAB, false);
        }
        else
        {
            pParametersAndPerformanceCurvesTab->SetTabItemVisible(PERFORMANCE_CURVE_TAB, true);
        }
    }

    void ProjectComponentDetailPanel::RefreshLegends()
    {
        std::vector<std::shared_ptr<gmepgcs::ILegend>> legendList;
        if (!(m_spDetailedComponent))
        {
            ShowLegends(legendList);
            return;
        }
        DBG_WARN_AND_RETURN_VOID_UNLESS(IProjectManager::Get(), L"IProjectManager::Get()为空", L"GMEP", L"2024-01-30");
        std::wstring projectId = IProjectManager::Get()->GetCurrentProjectId();
        std::wstring version = std::to_wstring(m_spDetailedComponent->Version);
        DBG_WARN_AND_RETURN_VOID_UNLESS( ProjectLocalComponentService::Get(), L" ProjectLocalComponentService::Get()为空", L"GMEP", L"2024-01-30");
        legendList =  ProjectLocalComponentService::Get()->GetLegends(m_spDetailedComponent.get());
        ShowLegends(legendList);
    }

    void ProjectComponentDetailPanel::StartEdit()
    {
        if (!m_spDetailedComponent)
        {
            return;
        }
        DBG_WARN_AND_RETURN_VOID_UNLESS(IProjectManager::Get(), L"IProjectManager::Get()为空", L"GMEP", L"2024-01-30");
        const std::wstring projectId = IProjectManager::Get()->GetCurrentProjectId();
        const std::wstring enterpriseId = IProjectManager::Get()->GetCurrentEnterpriseId();

        emit OnProjectComponentEditingRequired(projectId, enterpriseId, m_spDetailedComponent->Id, m_spDetailedComponent->Version, m_spDetailedComponent->Name);
    }

    void ProjectComponentDetailPanel::SetIsPrivateEnv(bool isPrivateEnv)
    {
        m_isPrivateEnv = isPrivateEnv;
    }
}